package com.beimi.game.rule;

import com.beimi.game.DizhuGame;
import com.beimi.game.module.GameCardModule;
import com.beimi.game.module.GamePlayerModule;
import com.beimi.game.player.GamePlayer;
import com.next.core.util.RandomUtil;

public class DizhuRule extends Rule {

	protected DizhuGame game;

	public void setGame(DizhuGame game) {
		this.game = game;
	}

	public void run() {
		switch (game.getState()) {
		case 0:
			deal();
			game.setState(1);
			break;

		case 1:
//			processPlay();
			break;

		case 2:

			break;

		default:
			break;
		}

	}

	@Override
	public void deal() {
		game.setDizhu(RandomUtil.nextInt(54));

		GamePlayer[] players = game.getModule(GamePlayerModule.class).getPlayers();
		int seatIndex = 0;
		for (int i = 0; i < 52; ++i) {
			int card = game.getModule(GameCardModule.class).pop();
			GamePlayer player = players[seatIndex];
			player.getCardModule().addMajong(card);
			if (i == game.getDizhu()) {
//				player.setDizhu(true);
			}

			seatIndex++;
			seatIndex %= 3;
		}
	}
}
